package com.mlingdu.supercloudreader.ui.gank;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;

import com.mlingdu.supercloudreader.R;
import com.mlingdu.supercloudreader.base.BaseFragment;
import com.mlingdu.supercloudreader.databinding.FragmentGankBinding;
import com.mlingdu.supercloudreader.ui.gank.child.EverydayFragment;
import com.mlingdu.supercloudreader.ui.gank.child.EverydayFragmentEx;
import com.mlingdu.supercloudreader.view.MyFragmentPageAdapter;

import java.util.ArrayList;

/**
 * 展示干货的页面，包含几个子Fragment，只写完GankFragment的第一个子Fragment
 */
public class GankFragment extends BaseFragment<FragmentGankBinding> {
	private ArrayList<String> mTitleList = new ArrayList<>(4);
	private ArrayList<Fragment> mFragments = new ArrayList<>(4);

	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		showLoading();
		initFragmentList();
		/**
		 * 注意使用的是：getChildFragmentManager，
		 * 这样setOffscreenPageLimit()就可以添加上，保留相邻3个实例，切换时不会卡
		 * 但会内存溢出，在显示时加载数据
		 */
		MyFragmentPageAdapter myAdapter = new MyFragmentPageAdapter(getChildFragmentManager(),mFragments,mTitleList);
		//set adapter
		bindingView.vpGank.setAdapter(myAdapter);
		bindingView.vpGank.setOffscreenPageLimit(3);
		myAdapter.notifyDataSetChanged();
		//set tab_layout
		bindingView.tabGank.setTabMode(TabLayout.MODE_FIXED);
		bindingView.tabGank.setupWithViewPager(bindingView.vpGank);
		showContentView();
		initRxBus();
	}

	@Override
	public int setContent() {
		return R.layout.fragment_gank;
	}
	private void initFragmentList(){
		mTitleList.add("每日推荐");
		mTitleList.add("福利");
		mTitleList.add("干货订制");
		mTitleList.add("大安卓");
		mFragments.add(new EverydayFragmentEx());
		mFragments.add(new EverydayFragment());
		mFragments.add(new EverydayFragment());
		mFragments.add(new EverydayFragment());
	}
	private void initRxBus(){

	}
}
